/**
 * 功能描述：ESP8266 PWM演示例程
 * @author 单片机菜鸟
 * @date 2018/10/25
 */
 
#define PIN_LED 12


int rotate_set = 0;
 //按键中断，增加设定转速
ICACHE_RAM_ATTR void PRRESS_KEY(){ 
  if(rotate_set == 0){
    rotate_set = 80; 
  }else if(rotate_set<120){
    rotate_set = rotate_set+10;
  }else{
    rotate_set = 126;
  }
}


//按键中断，减少设定转速
ICACHE_RAM_ATTR void PRRESS_KEY_decrease(){
  if(rotate_set == 126){
      rotate_set = 120; 
    }else if(rotate_set <= 80){
      rotate_set = 0;
    }else{
      rotate_set = rotate_set - 10;
    }  
}
void setup() {
  // 这里开始写初始化代码，只会执行一次
//  pinMode(PIN_LED,OUTPUT);
//  analogWrite(PIN_LED,0);
  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt(2), PRRESS_KEY, RISING);
  attachInterrupt(digitalPinToInterrupt(14), PRRESS_KEY_decrease, RISING);
  
}

void loop() {
  //这里写运行代码，重复执行
//  for(int val=0;val<1024;val++){
//     //占空比不断增大  亮度渐亮
//   analogWrite(PIN_LED,val);
//   delay(2);
//  }
    Serial.print("设定转速为：");
    Serial.println(rotate_set);
    delay(100); 
//  for(int val=1023;val>=0;val--){
//     //占空比不断变小  亮度渐暗
//   analogWrite(PIN_LED,1023);
//   delay(2);
//  }
}
